<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;">
<meta name="keywords" content="(www.eblog.site),博文分享，技术博文，影音推荐，美食分享，生活技巧，笑话大全"/>
<meta name="description" content="eBlog分享网(www.eblog.site)为广大朋友们提供有技术的博文，最新最热门的电影音乐。看到就流口水的美食，各种生活技巧，笑喘不过气的笑话！ "/>
<title>个人中心</title>
<link rel="shortcut icon" href="assets/manager/favicon.ico" /> 
<link href="assets/css/common.css" type="text/css" rel="stylesheet" />
<link href="assets/css/style.css" type="text/css" rel="stylesheet" />
</head>

<body>
<!-- common -->
<%@ include file="header.jsp"%>
<!-- common -->
<!-- wrap -->
<div class="wrap">
    <!-- content -->
    <div class="content">
        <!-- left -->
        <section id="ileft" class="lfloat">
            <div class="tagSelect">
                <span>标签分类：</span>
                <select id="tags">
                </select>
            </div>
            <ul id="LitemUl">
            </ul>
            <div class="pageBox"><p></p></div>
        </section>
        <!-- left -->
        <!-- right -->
        <section id="iright" class="rfloat">
            <div class="Ritem">
                <dl class="authorInfo">
                    <dt><a href="javascript:void(0)"><img id="userPic" src="assets/images/logo.png" alt="用户头像"></a></dt>
                    <dd>
                        <h4><a href="javascript:void(0)" id="author"></a></h4>
                        <p><span>原创<em id="ycTotal"></em></span><span>文章<em id="total"></em></span></p>
                    </dd>
                </dl>
                <p class="about">关于他：<span id="about"></span></p>
            </div>
            <div class="Ritem">
                <h3>推荐他的文章</h3>
                <ul class="RitemUl" id="tuijianA">
                </ul>
            </div>
            <div class="Ritem">
                <h3>他的热门文章</h3>
                <ul class="RitemUl" id="hotA">
                </ul>
            </div>
        </section>
        <!-- right -->
    </div>
    <!-- content -->
    <!-- copyright -->
    <%@ include file="footer.jsp"%>
    <!-- copyright -->
</div>
<!-- wrap -->
<script type="text/javascript" src="assets/scripts/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="assets/scripts/hr-jquery.js"></script>
<script src="assets/manager/js/pageBox.js"></script>
<script type="text/javascript">
	$(document).ready(function(){
		var $author;
		var $page=1;
    	var $pageSize=6;
    	var $tag = null;
    	var $title = null;
    	
		$.get("centerGetUser",function(data){
			$("#userPic").attr("src",data.userPic);
			$("#author").html(data.name);
			$("#about").html(data.aboutMe);
			$author=data.name;
			getTotal();
			getYCTotal();
			getArticles($page,$pageSize,$tag,$title,$author); 
			tagSelect();
			topFun($author);
		})
		
		function getTotal(){
			$.get("getArticlesByName?author="+$author,function(data){
				$("#total").html(data);
			});
		}
		
		function getYCTotal(){
			$.get("getYCArticlesByName?author="+$author,function(data){
				$("#ycTotal").html(data);
			});
		}
		
    	$.get("getTags",function(data){
	    	$tagsBox = $("#tags");
	    	var $firstOption = $("<option>全部</option>");
	    	$tagsBox.append($firstOption);
			for(var i=0;i<data.length;i++){
				var $option = $("<option>" + data[i] + "</option>");
				$tagsBox.append($option);
			}
		});
    	
    	
    	function getArticles(rpage,rpageSise,rqtag,rqtitle,rqauthor){
    		$.post("mgGetArticleByAuthor",
    			{page:rpage,pageSize:rpageSise,tag:rqtag,title:rqtitle,author:rqauthor},
    			function(data){
    			pageBox(data.pageInfo);
        		var $LitemUl = $("#LitemUl");
        		$("#LitemUl li").remove();
        		for(var i=0;i<data.pageInfo.list.length;i++){
            		var $article = data.pageInfo.list[i];
            		var $id = $article.id;
            		var $postD = $article.postD.split(".")[0];
            		var $li = $('<li class="Litem">'
                            	+ '<h2><a href="content?id='+$id+'" >' + $article.title + '</a></h2>'
                            	+ '<p class="intro">' + $article.intro + '</p>'
                            	+ '<dl class="info">'
                            		+ '<dd class="tag">'+$article.tag+'(<em>'+$article.type+'</em>)</dd>'
                            		+ '<dd class="postDate">' + $postD + '</dd>'
                            		+ '<dd class="readNum rfloat">'
                            		+ '<i class="read"></i><span class="readN">'+$article.readN+'</span>'
                            		+ '<i class="tuijian"></i><span class="tuijianN">'+$article.recommendN+'</span>'
                            	+ '</dd>'
                            	+ '</dl>'
                            + '</li>');
        			$LitemUl.append($li);
        		}
        	});
    	}
    	//分页
        $(".pageBox").on("click","a",function(){
        	var $cPage = $(this).attr("data-page");
        	var $maxPage =  $(".pageBox p").find("a:last").html();
        	if($cPage  == 0 || $(this).attr("class") == "active"){
        		return false;
        	}else if($page == $maxPage && ($(this).html() == "下一页" || $(this).html() == "尾页")){
        		return false;
        	}else if($page == 1 && ($(this).html() == "上一页" || $(this).html() == "首页")){
        		return false;
        	}
        	else{
        		$page = $cPage;
        		getArticles($page,$pageSize,$tag,$title,$author);
        	} 
        });
      	//分页
      	//tag
      	function tagSelect(){
      		$("#tags").change(function(){
        		$tag = $("#tags").val();
        		if($tag == "全部"){
        			$tag=null;
        		}
        		$page = 1;
        		$pageSize = 6;
        		getArticles($page,$pageSize,$tag,$title,$author);
        	});
      	}
    	//tag
    	
    	function topFun(author){
    		//阅读top
    	  	$.get("readTop?author="+author,function(data){
    	  		var $articles = data.pageInfo.list;
    	  		$("#hotA li").remove();
    	  		var $readTopBox = $("#hotA");
    	  		for(var i=0;i<$articles.length;i++){
    	  			var $li = $('<li><a href="content?id='+$articles[i].id+'">'+$articles[i].title+'</a></li>');
    	  			$readTopBox.append($li);
    	  		}
    	  	});
    	  	//阅读top
    	  	//推荐Top
    	  	$.get("tuijianTop?author="+author,function(data){
    	  		var $articles = data.pageInfo.list;
    	  		$("#tuijianA li").remove();
    	  		var $tuijianTopBox = $("#tuijianA");
    	  		for(var i=0;i<$articles.length;i++){
    	  			var $li = $('<li><a href="content?id='+$articles[i].id+'">'+$articles[i].title+'</a></li>');
    	  			$tuijianTopBox.append($li);
    	  		}
    	  	});
    	  	//推荐Top
    	}
	});
</script>
</body>
</html>
